<template>
    <div class="Card_Root">
        <div class="Card_video" @click="PlayVideo(id)">
            <!-- <el-image class="Card_video_poster" :src="posterDefault" :fit="fits" lazy /> -->
            <ImagePreviewer :width="'100%'" :height="'100%'" :imageUrl="posterDefault"></ImagePreviewer>
            <div class="Card_video_play">
                <VideoPlay class="video_info" />
            </div>
        </div>
        <div class="Card_Info">
            <el-tooltip class="box-item" effect="dark" placement="right">
                <template #content>{{ title }}</template>
                <el-text size="large" class="Card_title" truncated>标题:{{ title }}</el-text>
            </el-tooltip>
            <div class="Card_Mess">
                <!-- <span class="Card_Sub">简介:{{ subscribe }}</span> -->
                <el-tooltip class="box-item" effect="dark" placement="right">
                    <template #content>{{ subscribe }}</template>
                    <el-text class="Card_Sub" truncated>简介:{{ subscribe }}</el-text>
                </el-tooltip>
                <div class="info_box">
                    <el-tooltip class="box-item" effect="dark" placement="right">
                        <template #content>{{ author }}</template>
                        <span class="info author">作者:{{ author }}</span>
                    </el-tooltip>
                    <span class="info">上传日期:{{ date }}</span>
                    <span class="info">分区:{{ GetPartition }}</span>
                    <span class="info" v-if="history">点赞数:{{ like }}</span>
                </div>
                <span class="status">当前状态:
                    <el-text :type="statusShow">{{ statusText }}</el-text>
                </span>
            </div>
        </div>
        <div class="Card_Handle">
            <el-link type="success" v-if="!history" @click="AcceptTrend()">
                <slot name="Accept">审核通过</slot>
            </el-link>
            <el-link type="danger" v-else @click="OffShelf()">
                <slot name="offShelf">下架稿件</slot>
            </el-link>
            <el-link type="warning" @click="RejectTrend()">
                <slot name="Reject">驳回稿件</slot>
            </el-link>
        </div>
    </div>
</template>

<script setup>

import { ref, computed, toRefs, onMounted } from 'vue'
import devURL from '../Config/NetBaseConfig.js'
const fits = ['fill', 'contain', 'cover', 'none', 'scale-down']
import ImagePreviewer from './ImagePreviewer.vue';
//控制颜色
let textColor = ref('primary')


let props = defineProps({
    id: {
        type: String,
        required: true,
    },
    videoPoster: "",
    videoUrl: "",
    title: "",
    subscribe: "",
    author: "",
    date: "",
    partition: "",
    like: 0,
    status: '',
    history: {
        type: Boolean,
        default: false,
    },
})

let emits = defineEmits(['PlayerVideo', 'Accept', 'Reject', 'OffShelf'])

let data = computed(() => {
    return toRefs(props)
})

//测试模式下设置视频图片
let posterDefault = computed(() => {
    if (data.value.videoPoster.value === "" || data.value.videoPoster.value === null) {
        return new URL("../assets/Image/temp.png", import.meta.url).pathname
    }
    let url = data.value.videoPoster.value
    let result = url.substring(url.lastIndexOf("/video/"));
    return result
})
//* 投放分区(0-默认,1-动漫,2-游戏,3-音乐)
let GetPartition = computed(() => {
    let res = ''
    switch (props.partition) {
        case 0:
            res = '动漫'
            break;
        case 1:
            res = '游戏'
            break;
        case 2:
            res = '音乐'
            break;
        default:
            res = '默认'
            break;
    }
    return res
})


let videoURLTransform = computed(() => {
    if (data.value.videoUrl.value === "" || data.value.videoUrl.value === null) {
        return new URL("../assets/Image/temp.png", import.meta.url).pathname
    }
    let url = data.value.videoUrl.value
    let result = url.substring(url.lastIndexOf("/video/"));
    return `${devURL}${result}`
})

//通过当前稿件状态改变颜色
let statusShow = computed(() => {
    textColor.value = 'primary'
    switch (props.status) {
        case 0:
            textColor.value = 'primary'
            break;
        case 1:
            textColor.value = 'success'
            break;
        case 2:
            textColor.value = 'error'
            break;
        default:
            textColor.value = 'primary'
            break;
    }
    return textColor.value
})

let statusText = computed(() => {
    let text = '审核中'
    switch (props.status) {
        case 0:
            text = '审核中'
            break;
        case 1:
            text = '审核通过'
            break;
        case 2:
            text = '已被驳回'
            break;
        default:
            text = '审核中'
            break;
    }
    return text
})



//告知父组件播放视频
const PlayVideo = () => {
    let videoUrl = videoURLTransform.value
    let videoPoster = posterDefault.value
    emits('PlayerVideo', { videoPoster, videoUrl })
}

const AcceptTrend = () => {
    emits('Accept', props.id)
}

const RejectTrend = () => {
    emits('Reject', props.id)
}

const OffShelf = () => {
    emits('OffShelf', props.id)
}
</script>

<style lang='less' scoped>
.Card_Root {
    position: relative;
    padding: 0.35rem 0 0 0;
    width: 15rem;
    height: 18rem;
    border: 1px solid #ccc;
    border-radius: 1rem;
    display: flex;
    box-sizing: border-box;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.3rem;
    overflow: hidden;
    transition: all .5s ease;

    &:hover {
        transform: translateY(-0.2rem);
        box-shadow: 0 0 0.8rem 0.8rem rgba(93, 92, 92, .6);
        z-index: 100;
    }

    .Card_video {
        padding: 0 0.2rem 0 0.2rem;
        position: relative;
        border-top-left-radius: 1.05rem;
        border-top-right-radius: 1.05rem;
        flex: 4;
        width: 100%;
        height: 100%;
        // margin-bottom: 0.2rem;
        overflow: hidden;

        .Card_video_poster {
            width: 100%;
            height: 100%;
        }

        .Card_video_play {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);

            .video_info {
                width: 2rem;
                height: 2rem;
                color: #ccc;
            }
        }
    }

    .Card_Info {
        width: 100%;
        position: relative;
        flex: 2;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: start;
        flex-wrap: nowrap;
        padding: 0 0.2rem 0 0.2rem;
        // border-radius: 1px solid #ccc;

        .Card_title {
            width: 100%;
            user-select: none;
            cursor: pointer;
        }

        .Card_Mess {
            width: 95%;
            display: flex;
            flex-direction: column;
            justify-content: start;
            align-items: start;

            .Card_Sub {
                width: 100%;
                user-select: none;
                cursor: pointer;
            }

            .info_box {
                width: 100%;
                display: flex;
                flex-wrap: wrap;
                justify-content: start;
                align-items: center;
                border-radius: 1px solid #ccc;

                .info {
                    font-size: 16px;
                    color: #ccc;
                    margin-right: 0.5rem;
                }

                .author {
                    user-select: none;
                    cursor: pointer;
                }
            }

            .status {
                font-size: 0.8rem;
            }
        }

    }

    .Card_Handle {
        width: 100%;
        padding-bottom: 0.5rem;
        position: relative;
        flex: 1;
        border-top: 1px solid #ccc;
        display: flex;
        flex-grow: 1;
        justify-content: space-around;
        align-items: center;
    }
}
</style>